<template>
  <div class="full-box shadow-box padding-box">
    <OperateCommon :showBack="true" @back="goBack">
      <template #operate>
        <template v-if="pageType == 1">
          <el-button
            :disabled="form.report_status >= 90"
            type="success"
            @click="pass"
            >通过</el-button
          >
          <el-button
            :disabled="form.report_status == 5 || form.report_status == 90"
            type="danger"
            @click="dialog.reject = true"
            >退回</el-button
          >
        </template>

        <template v-if="pageType == 0">
          <el-button
            :disabled="form.report_status >= 10"
            type="success"
            @click="report"
            >上报</el-button
          >
          <el-button
            :disabled="form.report_status >= 10"
            type="primary"
            @click="temporaryStorage"
            >暂存</el-button
          >
        </template>

        <template v-if="pageType == 999">
          <el-button type="danger" @click="dangerEdit">修改</el-button>
        </template>
      </template>
    </OperateCommon>
    <div class="title">
      <div class="pname">
        <span>{{ form.project_name }}</span>
      </div>
      <div v-if="form.report_status >= 10" class="report-item">
        <div>
          <b>上报人：</b>
          {{ form.create_user_name || "无记录" }}
        </div>
        <div>
          <b>上报时间：</b>
          {{ form.create_time || "无记录" }}
        </div>
      </div>
    </div>
    <div>
      <el-tabs
        v-model="active"
        type="border-card"
        tab-position="top"
        @tab-click="tabsClick"
      >
        <el-tab-pane
          v-for="item in panes"
          :key="item.key"
          :label="item.label"
          :name="item.key"
        >
        </el-tab-pane>
        <div class="review-history" v-if="form.opinion">
          <el-alert
            class="review-history-item"
            v-for="(item, index) in form.opinion"
            :key="'h_' + index"
            :title="`审核人：${item.user_name}`"
            type="error"
            effect="light"
            show-icon
            :closable="false"
          >
            <div class="">
              <b>退回时间</b>
              {{ item.opdate }}
            </div>
            <div>
              <b>退回意见</b>
              {{ item.opinion }}
            </div>
          </el-alert>
        </div>
        <div class="content">
          <el-form
            :model="form"
            ref="form"
            :rules="rules"
            label-width="130px"
            :inline="false"
            :disabled="allowEdit()"
            size="normal"
          >
            <div class="d-row">
              <el-form-item label="开工状态" key="start_flag" prop="start_flag">
                <el-select style="width: 130px" v-model="form.start_flag">
                  <el-option :key="0" label="未开工" value="0"></el-option>
                  <el-option :key="1" label="已开工" value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="form.start_flag == 0" label="计划开工日期">
                <el-date-picker
                  v-model="form.plan_start_date"
                  type="date"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  disabled
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                v-if="form.start_flag == 1"
                label="开工日期"
                key="start_date"
                prop="start_date"
              >
                <el-date-picker
                  v-model="form.start_date"
                  type="date"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
            </div>
            <!-- 统计入库状态 -->
            <div class="d-row">
              <el-form-item
                label="统计入库状态"
                key="store_flag"
                prop="store_flag"
              >
                <el-select
                  style="width: 130px"
                  v-model="form.store_flag"
                  value-key=""
                  placeholder=""
                >
                  <el-option :key="0" label="未入库" value="0"></el-option>
                  <el-option :key="1" label="已入库" value="1"></el-option>
                  <el-option :key="2" label="不纳统" value="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                v-if="form.store_flag == 0 && form.start_flag == 1"
                label="开工未入库原因"
                key="not_store_reason"
                prop="not_store_reason"
              >
                <el-input
                  v-model="form.not_store_reason"
                  placeholder=""
                ></el-input>
              </el-form-item>
              <template v-if="form.store_flag == 1">
                <el-form-item
                  label="入库日期"
                  key="store_date"
                  prop="store_date"
                >
                  <el-date-picker
                    v-model="form.store_date"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期时间"
                  >
                  </el-date-picker>
                </el-form-item>
                <el-form-item
                  label="入库代码"
                  key="store_code"
                  prop="store_code"
                >
                  <el-input v-model="form.store_code" placeholder="">
                    <div slot="append">（多个代码用，隔开）</div>
                  </el-input>
                </el-form-item>
              </template>
              <el-form-item
                v-if="form.store_flag == 2"
                label="无法入库原因"
                key="not_store_reason"
                prop="not_store_reason"
              >
                <el-input
                  v-model="form.not_store_reason"
                  placeholder=""
                ></el-input>
              </el-form-item>
            </div>
            <!-- 完工状态 -->
            <div class="d-row">
              <el-form-item
                label="完工状态"
                key="finish_flag"
                prop="finish_flag"
              >
                <el-select
                  style="width: 130px"
                  v-model="form.finish_flag"
                  value-key=""
                  placeholder=""
                  clearable
                >
                  <el-option :key="0" label="未完工" value="0"></el-option>
                  <el-option :key="1" label="已完工" value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                v-if="form.finish_flag == 1"
                label="完工日期"
                key="finish_date"
                prop="finish_date"
              >
                <el-date-picker
                  v-model="form.finish_date"
                  type="date"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item label="计划完工日期">
                <el-date-picker
                  v-model="form.plan_end_date"
                  type="date"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  disabled
                >
                </el-date-picker>
              </el-form-item>
            </div>
            <!-- 投资额 -->
            <div v-if="form.start_flag == 1" class="d-row">
              <el-form-item
                label-width="160px"
                :label="active + ' 月份完成形象投资'"
                key="finish_investment"
                prop="finish_investment"
              >
                <!-- <el-input-number
                  v-model="form.finish_investment"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                >
                </el-input-number> -->
                <!-- temp change -->
                <el-input-number
                  v-model="form.finish_investment"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                  @change="calcInvestment"
                >
                </el-input-number>
                <span> （万元） </span>
              </el-form-item>
              <el-form-item
                label-width="180px"
                :label="'1 - ' + active + '月份完成形象投资'"
                key="finish_investment_year"
                prop="finish_investment_year"
              >
                <el-input-number
                  v-model="form.finish_investment_year"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                  :disabled="disabledForTemp()"
                >
                </el-input-number>
                <span> （万元） </span>
              </el-form-item>
              <el-form-item
                label-width="180px"
                label="开工累计完成形象投资"
                key="finish_investment_project"
                prop="finish_investment_project"
              >
                <el-input-number
                  v-model="form.finish_investment_project"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                  :disabled="disabledForTemp()"
                >
                </el-input-number>
                <span> （万元） </span>
              </el-form-item>
            </div>
            <!-- 统计入库 -->
            <div class="d-row" v-if="form.store_flag == '1'">
              <el-form-item
                label-width="160px"
                :label="active + ' 月份统计入库'"
                key="finish_investment_t"
                prop="finish_investment_t"
              >
                <!-- <el-input-number
                  v-model="form.finish_investment_t"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                  placeholder="绍兴核减数"
                >
                </el-input-number> -->
                <!-- temp change -->
                <el-input-number
                  v-model="form.finish_investment_t"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                  placeholder="绍兴核减数"
                  @change="calcInvestment"
                >
                </el-input-number>
                <span> （万元） </span>
              </el-form-item>
              <el-form-item
                label-width="180px"
                :label="'1 - ' + active + '月份累计统计入库'"
                key="finish_investment_t_year"
                prop="finish_investment_t_year"
              >
                <el-input-number
                  v-model="form.finish_investment_t_year"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                  :disabled="disabledForTemp()"
                >
                </el-input-number>
                <span> （万元） </span>
              </el-form-item>
              <el-form-item
                label-width="180px"
                label="开工累计统计入库"
                key="finish_investment_t_project"
                prop="finish_investment_t_project"
              >
                <el-input-number
                  v-model="form.finish_investment_t_project"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                  :disabled="disabledForTemp()"
                >
                </el-input-number>
                <span> （万元） </span>
              </el-form-item>
            </div>
            <div class="d-row">
              <el-form-item
                class="d-textarea"
                label="进度情况"
                key="progress"
                prop="progress"
              >
                <el-input
                  type="textarea"
                  v-model="form.progress"
                  placeholder="请具体文字说明项目进展的形象进度，避免只有百分比的描述"
                  :autosize="{
                    minRows: 3,
                    maxRows: 6,
                  }"
                ></el-input>
              </el-form-item>
              <el-form-item style="position:relative" label="进度照片" v-if="form.start_flag == 1">
                <div class="xing">*</div>
                <CommonUpload
                  tableName="month-progress"
                  useType="progress"
                  :showUploadBtn="true"
                  :disabled="allowEdit()"
                  :pid="form.id > 0 ? form.id : null"
                  @fileChange_chengying="fileChange_chengying"
                ></CommonUpload>
              </el-form-item>
              <el-form-item style="position:relative; width:100%" :inline-message="true" label="开工令" v-if="form.start_flag == 1">
                <div class="xing">*</div>
                <CommonUpload
                  tableName="kaigongling"
                  useType="progress"
                  :showUploadBtn="true"
                  :disabled="allowEdit()"
                  :pid="id > 0 ? id : null"
                  @fileChange_chengying="fileChange_chengying"
                ></CommonUpload>
              </el-form-item>
            </div>
            <div class="d-row">
              <el-form-item
                label="进度完成情况"
                key="finish_status"
                prop="finish_status"
              >
                <el-select
                  style="width: 100px"
                  v-model="form.finish_status"
                  value-key=""
                  placeholder=""
                >
                  <el-option :key="0" label="超前" value="超前"></el-option>
                  <el-option :key="1" label="正常" value="正常"></el-option>
                  <el-option :key="2" label="滞后" value="滞后"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                v-if="form.finish_status == '滞后'"
                label-width="10px"
                label=""
                key="lag_months"
                prop="lag_months"
              >
                <el-input-number
                  v-model="form.lag_months"
                  size="normal"
                  label=""
                  :step="1"
                  :precision="0"
                  :controls="true"
                  controls-position="right"
                >
                </el-input-number>
                （ 月 ）
              </el-form-item>
              <div class="d-row-child">
                <el-form-item
                  v-if="form.finish_status == '滞后'"
                  class="d-textarea"
                  label="滞后原因"
                  key="lag_reason"
                  prop="lag_reason"
                >
                  <el-input
                    type="textarea"
                    v-model="form.lag_reason"
                    placeholder=""
                    :autosize="{
                      minRows: 3,
                      maxRows: 6,
                    }"
                  ></el-input>
                </el-form-item>
              </div>
            </div>
            <el-form-item label="是否存在新问题" prop="existDifficulty">
              <el-select
                style="width: 100px"
                v-model="form.existDifficulty"
                value-key=""
                placeholder=""
                :disabled="haveNewQuestion()"
              >
                <el-option :key="0" label="否" value="否"></el-option>
                <el-option :key="1" label="是" value="是"></el-option>
              </el-select>
              <el-button
                v-show="form.existDifficulty == '是'"
                style="margin-left: 10px"
                icon="el-icon-plus"
                type="primary"
                size="medium"
                @click="addQuestion"
                >新增问题</el-button
              >
            </el-form-item>
            <el-form-item label="" label-width="0">
              <el-table :data="question" border stripe>
                <el-table-column
                  prop=""
                  align="center"
                  label="当前存在问题"
                  width="200"
                >
                  <el-table-column
                    v-for="col in questionColumns"
                    :prop="col.prop"
                    :key="col.id"
                    :label="col.label"
                    :width="col.width"
                    :min-width="col.minWidth"
                    :align="col.align"
                  >
                  </el-table-column>
                  <el-table-column
                    label="操作"
                    width="150"
                    align="center"
                    fixed="right"
                    v-if="
                      form.report_status == '' ||
                      parseInt(form.report_status) < 10
                    "
                  >
                    <template slot-scope="scope">
                      <el-button
                        type="primary"
                        size="mini"
                        :disabled="!scope.row.nqid"
                        @click="editQuestion(scope)"
                        >编辑</el-button
                      >
                      <el-button
                        icon="el-icon-minus"
                        type="danger"
                        size="mini"
                        :disabled="!scope.row.nqid"
                        @click="removeQuestion(scope)"
                      ></el-button>
                    </template>
                  </el-table-column>
                </el-table-column>
              </el-table>
            </el-form-item>
            <el-form-item label="是否存在安全事故" label-width="140px" prop="existSafeAccident">
                  <el-select
                      style="width: 100px"
                      v-model="form.existSafeAccident"
                      value-key=""
                      placeholder=""
                  >
                      <el-option :key="0" label="否" value="否"></el-option>
                      <el-option :key="1" label="是" value="是"></el-option>
                  </el-select>
                  <el-button
                      v-show="form.existSafeAccident == '是'"
                      style="margin-left: 10px"
                      icon="el-icon-plus"
                      type="primary"
                      size="medium"
                      @click="dialog.safeAccident=true"
                  >新增</el-button
                  >
              </el-form-item>
            <el-form-item label="" label-width="0">
                  <el-table :data="accidentList" border stripe>
                      <el-table-column
                          v-for="col in accidentList_header"
                          :prop="col.prop"
                          :label="col.label"
                          :width="col.width"
                      >
                      </el-table-column>
                      <el-table-column
                          label="操作"
                          width="150"
                          align="center"
                          fixed="right"
                          v-if="
                      form.report_status == '' ||
                      parseInt(form.report_status) < 10
                    "
                      >
                          <template slot-scope="scope">
                              <el-button
                                  type="primary"
                                  size="mini"
                                  @click="editSafeAccident(scope.row)"
                              >编辑</el-button
                              >
                              <el-button
                                  icon="el-icon-minus"
                                  type="danger"
                                  size="mini"
                                  @click="removeSafeAccident(scope.row)"
                              ></el-button>
                          </template>
                      </el-table-column>
                  </el-table>
              </el-form-item>
          </el-form>
        </div>
      </el-tabs>
    </div>
    <!-- question form -->
    <el-dialog
      title="项目问题"
      width="700px"
      :visible.sync="dialog.questionForm"
      :close-on-click-modal="false"
      @close="dialog.questionForm = false"
    >
      <el-form
        :model="questionForm"
        ref="questionForm"
        :rules="questionRules"
        label-width="80px"
        :inline="false"
      >
        <el-form-item label="问题分类" prop="problem_type">
          <el-select
            v-model="questionForm.problem_type"
            value-key=""
            placeholder=""
          >
            <el-option
              v-for="item in questionOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="存在问题" prop="problem_desc">
          <el-input
            type="textarea"
            v-model="questionForm.problem_desc"
            placeholder=""
            :autosize="{
              minRows: 3,
              maxRows: 6,
            }"
          ></el-input>
        </el-form-item>
        <el-form-item label="协调情况" prop="concert_content">
          <el-input
            type="textarea"
            v-model="questionForm.concert_content"
            placeholder=""
            :autosize="{
              minRows: 3,
              maxRows: 6,
            }"
          ></el-input>
        </el-form-item>
        <el-form-item label="工作建议" prop="proposal">
          <el-input
            type="textarea"
            v-model="questionForm.proposal"
            placeholder=""
            :autosize="{
              minRows: 3,
              maxRows: 6,
            }"
          ></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="saveQuestion">保存</el-button>
          <el-button type="" @click="dialog.questionForm = false"
            >返回</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      title="进度退回"
      :visible.sync="dialog.reject"
      width="700px"
      @close="dialog.reject = false"
    >
      <div>
        <b>退回原因</b>
        <el-input
          style="margin-top: 10px"
          type="textarea"
          v-model="rejectReason"
          placeholder="请输入退回原因"
          :autosize="{
            minRows: 3,
            maxRows: 6,
          }"
        ></el-input>
        <div class="btn-group">
          <el-button type="danger" @click="sendBack">退回</el-button>
          <el-button @click="dialog.reject = false">取消</el-button>
        </div>
      </div>
    </el-dialog>
    <el-dialog
          title="安全事故"
          width="700px"
          :visible.sync="dialog.safeAccident"
          :close-on-click-modal="false"
          @close="closeSafeAccident"
      >
        <GenerateMain :gData="gData"></GenerateMain>
        <div style="text-align: right;margin-top: 20px;">
            <el-button type="primary" @click="saveSafeAccident">保存</el-button>
            <el-button type="" @click="closeSafeAccident">返回</el-button>
        </div>
      </el-dialog>
  </div>
</template>

<script>
import Big from "big.js";
import {
  getProgressDetails,
  postProgressReview,
  postProgressSave,
} from "@/api/MajorProjectPromotion/Index";
import QuestionType from "@/mixins/QuestionType";
import { required } from "@/utils/eValidate";
import OperateCommon from "@/components/Common/OperateCommon.vue";
import LinkTo from "@/mixins/LinkTo";
import CommonUpload from "@/components/Common/CommonUpload.vue";
import uploadMixin from "@/components/GenerateForm/uploadMixin";
import {commonSave, getTableField} from "@/api/Index";
import GenerateMain from "@/components/GenerateForm/GenerateMain.vue";
export default {
  name: "ProgressDetails",
  components: { OperateCommon, CommonUpload,GenerateMain },
  mixins: [QuestionType, LinkTo, uploadMixin],
  data() {
    return {
      pageType: 0,
      active: 0,
      id: 0,
      current: {
        year: new Date().getFullYear(),
        month: new Date().getMonth() + 1,
      },
      fileschange:[],
      panes: panes,
      form: JSON.parse(JSON.stringify(form)),
      originalInvestment: {
        finish_investment_year: 0,
        finish_investment_project: 0,
        finish_investment_t_year: 0,
        finish_investment_t_project: 0,
      },
      rules: {
        start_flag: [required],
        start_date: [required],
        store_flag: [required],
        store_code: [required],
        store_date: [required],
        not_store_reason: [required],
        finish_flag: [required],
        finish_date: [required],
        progress: [required],
        finish_status: [required],
        lag_months: [required],
        lag_reason: [required],
        existDifficulty: [required],
        existSafeAccident: [required],
        finish_investment: [required],
        finish_investment_year: [required],
        finish_investment_project: [required],
        finish_investment_t: [required],
        finish_investment_t_year: [required],
        finish_investment_t_project: [required],
      },
      questionColumns: questionColumns,
      questionForm: {
        nqid: new Date().getTime(),
        problem_type: "",
        problem_desc: "",
        concert_content: "",
        proposal: "",
      },
      question: [],
      questionRules: {
        problem_type: [required],
        problem_desc: [required],
        concert_content: [required],
        proposal: [required],
      },
      dialog: {
        questionForm: false,
        reject: false,
        pass: false,
        safeAccident: false,
      },
      rejectReason: "",
      accidentList:[],
      accidentList_header:[
          {label:'事故类型',prop:'type',width:150},
          {label:'事故发生原因',prop:'reason'},
          {label:'事故描述',prop:'content'},
          {label:'后续措施',prop:'follow_up'},
      ],
      gData:[],
    };
  },
  methods: {
    //安全事故保存
    saveSafeAccident() {
        let postData = {
            project_id:this.id,
            id:'0',
            table_name:'t_accident',
            year:this.current.year,
            month:this.current.month,
        }
        this.recursionValue(this.gData,postData);
        commonSave(postData).then((res) => {
            if (res.code == 0) {
                postData.id = res.data+'';
                this.accidentList.push(postData);
                this.closeSafeAccident();
            }
        });
    },
    //获取安全事故表单
    initField() {
          getTableField({ tableName:'t_accident' }).then((res) => {
              if (res.code == 0) {
                  this.gData = res.data;
              }
          });
      },
    //编辑安全事故
    editSafeAccident(row){
        this.dialog.safeAccident = true;
        this.gData.forEach(item => item.bindModel = row[item.dbField]);
    },
    //删除安全事故
    removeSafeAccident(row){
        row.status = 1;
        row.table_name = 't_accident';
        commonSave(row).then((res) => {
            if (res.code == 0) {
                let index = this.accidentList.findIndex(item => item.id === row.id);
                this.accidentList.splice(index,1);
            }
        });
    },
    recursionValue(val,postData) {
        return val.map((i) => {
            if (i.children) {
                this.recursionValue(i.children,postData);
            } else {
                if (i.dbField) {
                    postData[i.dbField] = i.bindModel;
                }
            }

            return i;
        });
    },
    //关闭安全事故弹框
    closeSafeAccident(){
        this.dialog.safeAccident = false;
        setTimeout(() => this.gData.forEach(item => item.bindModel = ''),300);
    },
    tabsClick(val) {
      this.initData(val.name);

      // const _path = `/majorProjectPromotion/progressDetails/${this.id}/${this.current.year}/${val.name}/${this.pageType}`;

      // console.log("before", this.$route);

      // this.$route.params.month = val.name;
      // this.$route.path = _path;

      // this.$router.push({
      //   path: `/majorProjectPromotion/progressDetails/${this.id}/${this.current.year}/${val.name}/${this.pageType}`,
      //   query: { change: val.name },
      // });

      // console.log("after", this.$route);
    },
    initData(month) {
      getProgressDetails({
        project_id: this.id,
        year: this.current.year,
        month: month,
      }).then((res) => {
        if (res.code == 0) {
          // this.form = res.data;
          this.$set(
            this,
            "form",
            Object.assign(JSON.parse(JSON.stringify(form)), res.data)
          );
          if (res.data.problemList && res.data.problemList.length > 0) {
            this.form.existDifficulty = "是";
            this.$set(this, "question", res.data.problemList);
          } else {
            this.form.existDifficulty = "否";
            this.$set(this, "question", []);
          }
          if (res.data.accidentList && res.data.accidentList.length > 0) {
              this.form.existSafeAccident = "是";
              this.accidentList = res.data.accidentList;
          } else {
              this.form.existSafeAccident = "否";
              this.accidentList = [];
          }

          if (this.form.report_status == "") {
            this.form.finish_investment = this.resetNumber(
              this.form.finish_investment
            );
            this.form.finish_investment_year = this.resetNumber(
              this.form.finish_investment_year
            );
            this.form.finish_investment_project = this.resetNumber(
              this.form.finish_investment_project
            );
            this.form.finish_investment_t = this.resetNumber(
              this.form.finish_investment_t
            );
            this.form.finish_investment_t_year = this.resetNumber(
              this.form.finish_investment_t_year
            );
            this.form.finish_investment_t_project = this.resetNumber(
              this.form.finish_investment_t_project
            );
          }

          this.originalInvestment.finish_investment_year =
            res.data.last_finish_investment_year;
          this.originalInvestment.finish_investment_project =
            res.data.last_finish_investment_project;
          this.originalInvestment.finish_investment_t_year =
            res.data.last_finish_investment_t_year;
          this.originalInvestment.finish_investment_t_project =
            res.data.last_finish_investment_t_project;

          this.form.report_month = month;
          this.$nextTick(() => {
            this.$refs.form.clearValidate();
          });
        }
      });
    },
    resetNumber(num) {
      if (typeof num == "string" && num.trim() == "") {
        return undefined;
      }
      if (
        typeof num == "string" &&
        (parseInt(num) == 0 || parseInt(num) == NaN)
      ) {
        return undefined;
      }
      if (typeof num == "number" && parseInt(num) == 0) {
        return undefined;
      }

      return num;
    },
    calcInvestment() {
      if (this.pageType == 999) {
        return;
      }

      this.form.finish_investment_year = new Big(
        this.form.finish_investment || 0
      ).plus(new Big(this.originalInvestment.finish_investment_year || 0));

      this.form.finish_investment_project = new Big(
        this.form.finish_investment || 0
      ).plus(new Big(this.originalInvestment.finish_investment_project || 0));

      this.form.finish_investment_t_year = new Big(
        this.form.finish_investment_t || 0
      ).plus(new Big(this.originalInvestment.finish_investment_t_year || 0));

      this.form.finish_investment_t_project = new Big(
        this.form.finish_investment_t || 0
      ).plus(new Big(this.originalInvestment.finish_investment_t_project || 0));
    },
    saveQuestion() {
      this.$refs.questionForm.validate((valid) => {
        if (valid) {
          this.question.push(JSON.parse(JSON.stringify(this.questionForm)));
          this.dialog.questionForm = false;
        }
      });
    },
    addQuestion() {
      this.dialog.questionForm = true;
      this.$nextTick(() => {
        this.$refs.questionForm.resetFields();
        this.questionForm.nqid = new Date().getTime();
      });
    },
    editQuestion(scope) {
      this.questionForm = scope.row;
      this.dialog.questionForm = true;
    },
    removeQuestion(scope) {
      this.question = this.question.filter((i) => {
        return i.nqid != scope.row.nqid;
      });
    },
    temporaryStorage() {
      this.form.report_status = 0;
      this.saveProgress();
    },
    fileChange_chengying(res,type){
      if(type === 'delete'){
        let index = this.fileschange.findIndex(item => {
          return item.uid===res[0].uid || (item.annex_id && item.annex_id===res[0].annex_id)
        });
        this.fileschange.splice(index,1);
      }else{
        this.fileschange.push(...res);
      }
    },
    report() {
      // if ([6, 7].indexOf(parseInt(this.active)) == -1) {
      //   this.$message.error("当前仅支持6、7月份的进度上报");
      //   return;
      // }
      let files = [...this.$store.state.files.unBindFiles,...this.fileschange];
      if (this.form.start_flag==='1' && (!files || files.length === 0)) {
          let j=[false,false];
          for(let i=0;i<files.length;i++){
              if (files[i].table_name=="month-progress"){
                  j[0] = true;
              }
              if(files[i].table_name=="kaigongling") {
                  j[1] = true;
              }
          }
          if(j.includes(false)){
              return this.$message({
                  message: '需要上传的文件不能为空！',
                  type: 'warning'
              });
          }
      }
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$confirm(
            `当前上报的是【${this.form.report_month}】月的进度，上报后无法修改，请确认上报信息准确无误`,
            "上报确认",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "success",
            }
          )
            .then(() => {
              this.form.report_status = 10;
              this.saveProgress();
            })
            .catch(() => {
              this.$message({
                type: "info",
                message: "已取消",
              });
            });
        }
      });
    },
    saveProgress() {
      this.form.project_id = this.id;
      this.form.question = this.question.filter((i) => {
        return i.nqid != undefined;
        
      });

      postProgressSave(this.form).then((res) => {
        if (res.code == 0) {
          this.$message.success("保存成功");
          this.checkFile(res.data);
          this.initData(this.form.report_month);
        }
      });
    },
    dangerEdit() {
      delete this.form.create_user_name;
      delete this.form.create_time;


      postProgressSave(this.form).then((res) => {
        if (res.code == 0) {
          this.$message.success("修改成功");
          this.checkFile(res.data);
          this.initData(this.form.report_month);
        }
      });
    },
    pass() {
      this.$confirm("确定通过当前进度吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "success",
      })
        .then(() => {
          postProgressReview({
            id: this.form.id,
            status: 100,
          }).then((res) => {
            if (res.code == 0) {
              this.$message.success("通过成功");
              this.initData(this.current.month);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    sendBack() {
      postProgressReview({
        id: this.form.id,
        status: 5,
        opinion: this.rejectReason,
      }).then((res) => {
        if (res.code == 0) {
          this.$message.success("退回成功");
          this.initData(this.current.month);
          this.dialog.reject = false;
        }
      });
    },
    haveNewQuestion() {
      if (this.question && this.question.length == 0) {
        return false;
      }
      let newQuestion = false;
      this.question.forEach((i) => {
        if (i.nqid) {
          newQuestion = true;
          return;
        }
      });
      return newQuestion;
    },
    goBack() {
      switch (parseInt(this.pageType)) {
        case 0:
          this.linkTo("/progressDeclare");
          break;
        case 1:
          this.linkTo("/progressReview");
          break;
        case 999:
          this.linkTo("/BmMonthProgress");
          break;
        default:
          break;
      }
    },
    // temp disabled
    disabledForTemp() {
      // return [6, 7].indexOf(parseInt(this.form.report_month)) == -1;

      if (this.pageType == 999) {
        return false;
      }

      return true;
    },
    allowEdit() {
      switch (parseInt(this.pageType)) {
        case 0:
        case 1:
        case 2:
          if (this.form.report_status >= 10) {
            return true;
          }
        case 999:
          return false;
        default:
          return false;
      }
    },
  },
  created() {
    this.id = this.$route.params.id;
    this.current.year = this.$route.params.year;
    this.active = this.current.month = "" + parseInt(this.$route.params.month);
    this.pageType = this.$route.params.type;

    this.initData(this.current.month);
    this.initField();
    if (this.pageType == 999) {
      this.rules = null;
    }
  },
  watch: {
    $route(to, from) {
      this.$router.go(0);
    },
  },
};
const panes = [
  { label: "1月", key: "1" },
  { label: "2月", key: "2" },
  { label: "3月", key: "3" },
  { label: "4月", key: "4" },
  { label: "5月", key: "5" },
  { label: "6月", key: "6" },
  { label: "7月", key: "7" },
  { label: "8月", key: "8" },
  { label: "9月", key: "9" },
  { label: "10月", key: "10" },
  { label: "11月", key: "11" },
  { label: "12月", key: "12" },
];

const form = {
  report_year: "",
  report_month: "",
  start_flag: "", // 开工状态 0 未开工 1 已开工
  start_date: "", // 开工日期
  store_flag: "", // 统计入库标记
  store_code: "", // 统计入库代码
  store_date: "", // 统计入库日期
  not_store_reason: "", // 开工未入库原因
  finish_flag: "", // 完工状态 0 未完工 1 已完工
  finish_date: "", // 完工时间
  progress: "", // 进度情况
  finish_investment: 0, // 当月完成形象投资
  finish_investment_year: 0, // 当年完成形象投资
  finish_investment_project: 0, // 项目累计完成形象投资
  finish_investment_t: 0, // 当月统计入库
  finish_investment_t_year: 0, // 当年累计统计入库
  finish_investment_t_project: 0, // 项目统计入库
  finish_status: "", // 进度状态  超前、正常、滞后
  lag_months: "", // 滞后月数
  lag_reason: "", // 滞后原因
  report_status: "", // 上报状态 0 暂存 5 退回 10 待审核 100 通过
  existDifficulty: "", // 是否存在问题 是 否
  existSafeAccident:'',  // // 是否存在安全事故 是 否
  question: [], // 存在问题
};

const question = {
  problem_type: "", // 问题分类
  problem_desc: "", // 存在问题
  concert_content: "", // 协调情况
  proposal: "", // 工作建议
};

const questionColumns = [
  {
    id: "1",
    prop: "problem_type",
    label: "问题分类",
    width: "150",
    minWidth: "",
    align: "center",
  },
  {
    id: "2",
    prop: "problem_desc",
    label: "存在问题",
    width: "",
    minWidth: "300",
    align: "center",
  },
  {
    id: "3",
    prop: "concert_content",
    label: "协调情况",
    width: "",
    minWidth: "300",
    align: "center",
  },
  {
    id: "4",
    prop: "proposal",
    label: "工作建议",
    width: "",
    minWidth: "300",
    align: "center",
  },
];
</script>

<style lang="scss" scoped>
.xing{
  position: absolute;
  color: red;
  top: 0px;
    left: -82px;
}
.form-row {
  display: flex;
  flex-wrap: wrap;
}
.d-model {
  margin-bottom: 10px;
  font-weight: 600;
}
.d-row {
  margin: 20px 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  border-bottom: 1px solid #eee;
  color: #000;
  :deep(.el-form-item) {
    margin-bottom: 20px;
  }
}
.d-row-child {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}
.d-textarea {
  width: 100%;
  margin: 0 auto;
}

:deep(.el-input__inner) {
  color: #000;
}

.title {
  min-height: 50px;
  .pname {
    text-align: center;
    font-size: 24px;
    font-weight: 600;
    > span {
      box-sizing: border-box;
      padding-bottom: 5px;
      border-bottom: 1px solid #ccc;
    }
  }
  .report-item {
    margin-top: 10px;
    margin-bottom: 10px;
    display: flex;
    justify-content: center;
    > div {
      display: inline-block;
      &:nth-child(1) {
        margin-right: 20px;
      }
    }
  }
}
.btn-group {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}
.review-history {
  margin-bottom: 10px;
}
.review-history-item {
  margin-bottom: 5px;
}

.last-bg {
  box-sizing: border-box;
  padding: 10px 0;
  width: 100%;
  min-height: 60px;
  background-color: rgb(217, 236, 255);
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  > div {
    &:nth-child(1) {
      width: 400px;
    }
    > label {
      font-size: 13px;
      margin-right: 12px;
    }
    > span {
      font-size: 13px;
    }
  }
}
</style>
